import fetch from 'common/src/utils/fetch';

const pageUrl = '/api/electionservice/graduateInfo/listGraduateExamInfo';
const examRoomPageUrl =
    '/api/electionservice/graduateInfo/listExamRoomByExamInfoId';
const examClassPageUrl = '/api/electionservice/graduateInfo/listTeachingClass';
const examStuPageUrl = '/api/electionservice/graduateInfo/listStudent';
const examTeaPageUrl = '/api/electionservice/graduateInfo/listTeachingClass';
/**
 *新增
 */
function add(data) {
    return fetch({
        url: '/api/electionservice/graduateInfo/addgraduateInfo',
        method: 'post',
        data: data
    });
}

/**
 *编辑
 */
function edit(data) {
    return fetch({
        url: '/api/electionservice/graduateInfo/editgraduateInfo',
        method: 'post',
        data: data
    });
}

/**
 *删除
 */
function del(data) {
    return fetch({
        url: '/api/electionservice/graduateInfo/deletegraduateInfo',
        method: 'post',
        data: data
    });
}

/**
 *保存考试时间
 */
function saveExamTime(data) {
    return fetch({
        url: '/api/electionservice/graduateInfo/saveExamTimeAndBatch',
        method: 'post',
        data: data
    });
}

/**
 *保存考场
 */
function saveExamRoom(data, examInfoIds) {
    return fetch({
        url:
            '/api/electionservice/graduateInfo/saveExamRoom?examInfoIds=' +
            examInfoIds,
        method: 'post',
        data: data
    });
}

/**
 *保存监考老师
 */
function saveTeacher(data, examRoomId, examInfoIds) {
    return fetch({
        url:
            '/api/electionservice/graduateInfo/saveTeacher?examRoomId=' +
            examRoomId +
            '&examInfoIds=' +
            examInfoIds,
        method: 'post',
        data: data
    });
}

/**
 *保存排考班级
 */
function saveTeachingClass(data) {
    return fetch({
        url: '/api/electionservice/graduateInfo/saveTeachingClass',
        method: 'post',
        data: data
    });
}

/**
 *保存排考学生
 */
function saveStudent(data, examRoomId) {
    return fetch({
        url:
            '/api/electionservice/graduateInfo/saveStudent?examRoomId=' +
            examRoomId,
        method: 'post',
        data: data
    });
}

/**
 *清空考场（学生）
 */
function cleanStudentByRoomId(data) {
    return fetch({
        url: '/api/electionservice/graduateInfo/cleanStudentByRoomId',
        method: 'post',
        data: data
    });
}

/**
 *删除考场
 */
function deleteRoom(data, examInfoIds) {
    return fetch({
        url:
            '/api/electionservice/graduateInfo/deleteRoom?examInfoIds=' +
            examInfoIds,
        method: 'post',
        data: data
    });
}

/**
 *type 0 撤回 1 发布
 */
function reback(data, type) {
    return fetch({
        url:
            '/api/electionservice/graduateInfo/releaseOrRebackGraduateExamInfo?type=' +
            type,
        method: 'post',
        data: data
    });
}

/**
 *导出
 */
function exportExam(data) {
    return fetch({
        url: '/api/electionservice/graduateInfo/export',
        method: 'post',
        data: data
    });
}
/**
 * 获取key
 */
function exportStatus(key) {
    return fetch({
        url: '/api/electionservice/reportManagement/result/' + key,
        method: 'get'
    });
}
/**
 *根据考场ID查询考场名单
 */
function getExamStudentByRoomId(id) {
    return fetch({
        url:
            '/api/electionservice/graduateInfo/getExamStudentByRoomId?id=' + id,
        method: 'get'
    });
}

/**
 * 根据开始时间结束时间查询当前时间位于哪个学期，第几周，周几，所在节次
 */
function dayAndWorkTime(beginTime, endTime) {
    return fetch({
        url:
            `/api/baseresservice/schoolCalendar/dayAndWorkTime?beginTime=` +
            beginTime +
            `&endTime=` +
            endTime,
        method: 'get'
    });
}

/**
 *自动排考
 */
function autoAllocation(data) {
    return fetch({
        url: '/api/electionservice/graduateInfo/autoAllocation',
        method: 'post',
        data: data
    });
}

/**
 * 根据key循环去redis取数据
 */
function getRedisKey(key) {
    return fetch({
        url: '/api/electionservice/graduateInfo/result/' + key,
        method: 'get',
        showMask:false
    });
}

/**
 *实时查询排考人数
 */
function getExamStudentNumber(data) {
    return fetch({
        url: '/api/electionservice/graduateInfo/getExamStudentNumber',
        method: 'post',
        data: data
    });
}

/**
 * 修改研究生排考信息
 */
function editGraduateExam(id) {
    return fetch({
        url: '/api/electionservice/graduateInfo/editGraduateExam?id=' + id,
        method: 'get'
    });
}

/**
 * 修改排考时间，并且删除教室
 */
function saveExamTimeAndDeleteExamRoom(data) {
    return fetch({
        url: '/api/electionservice/graduateInfo/saveExamTimeAndDeleteExamRoom',
        method: 'post',
        data: data
    });
}

/**
 *获取监考老师数量
 */
function getMonitotTeacherNumber(roomCapcity) {
    return fetch({
        url:
            '/api/electionservice/graduateMonitorTeacher/getMonitotTeacherNumber?roomCapcity=' +
            roomCapcity,
        method: 'get'
    });
}

export default {
    add: add,
    edit: edit,
    del: del,
    saveExamTime: saveExamTime,
    // examRooms: examRooms,
    pageUrl: pageUrl,
    examRoomPageUrl: examRoomPageUrl,
    examClassPageUrl: examClassPageUrl,
    examStuPageUrl: examStuPageUrl,
    examTeaPageUrl: examTeaPageUrl,
    saveExamRoom: saveExamRoom,
    saveTeacher: saveTeacher,
    saveTeachingClass: saveTeachingClass,
    saveStudent: saveStudent,
    // examStudent: examStudent,
    // examTeahchingClass: examTeahchingClass,
    cleanStudentByRoomId: cleanStudentByRoomId,
    deleteRoom: deleteRoom,
    exportExam: exportExam,
    exportStatus: exportStatus,
    getExamStudentByRoomId: getExamStudentByRoomId,
    reback: reback,
    dayAndWorkTime: dayAndWorkTime,
    autoAllocation: autoAllocation,
    getRedisKey: getRedisKey,
    getExamStudentNumber: getExamStudentNumber,
    getMonitotTeacherNumber: getMonitotTeacherNumber,
    editGraduateExam: editGraduateExam,
    editExamTime: saveExamTimeAndDeleteExamRoom
};
